/*
 * Created by SharpDevelop.
 * User: GZamor1
 * Date: 8/16/2007
 * Time: 4:04 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using MediaPortal.GUI.Library;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
using MediaPortal.Player;
using System.Collections.Generic;
//using MediaPortal.Utils.Services;
using MediaPortal.GUI.View ;
using MediaPortal.Dialogs;
using MediaPortal.Util;
using System.Xml;
using System.Xml.XPath;
using System.ComponentModel;
using System.Threading;
using OnlineVideos.Database;

namespace OnlineVideos
{
	/// <summary>
	/// Description of FavoriteUtil.
	/// </summary>
	public class FavoriteUtil:SiteUtilBase
	{
		public FavoriteUtil()
		{
		}
		
		public override string getSiteId()
		{
			return "100";
		}
		public override string getUrl(OnlineVideos.GUIOnlineVideos.VideoInfo video, OnlineVideos.GUIOnlineVideos.SiteSettings foSite)
		{		
			
			GUIOnlineVideos.SiteSettings loSite = OnlineVideoSettings.getInstance().moSiteList[video.SiteID];
			return SiteUtilFactory.getSiteUtil(video.SiteID).getUrl(video,loSite);;
		}
		public override List<GUIOnlineVideos.VideoInfo> getVideoList(string fsUrl)
		{
			fsUrl = fsUrl.Substring(4);
			FavoritesDatabase db = FavoritesDatabase.getInstance();
			List<GUIOnlineVideos.VideoInfo> loVideoList;
			if(String.IsNullOrEmpty(fsUrl)){
				loVideoList = db.getAllFavoriteVideos();
			}else if(fsUrl.StartsWith("%")){
				fsUrl = fsUrl.Substring(1);
				loVideoList = db.searchFavoriteVideos(fsUrl);
			}else{
				loVideoList = db.getSiteFavoriteVideos(fsUrl);
			}
			//GUIOnlineVideos.VideoInfo video;
			
			
			return loVideoList;
		}
		public override List<OnlineVideos.GUIOnlineVideos.RssLink> getDynamicCategories(string lsUrl)
		{
			GUIOnlineVideos.RssLink all = new GUIOnlineVideos.RssLink();
			all.name = "All";
			all.url = "fav:";
			List<OnlineVideos.GUIOnlineVideos.RssLink> cats = new List<OnlineVideos.GUIOnlineVideos.RssLink>();
			cats.Add(all);
			
			FavoritesDatabase db = FavoritesDatabase.getInstance();
			string [] lsSiteIds = db.getSiteIDs();
			Dictionary <String, GUIOnlineVideos.SiteSettings> loSiteList = OnlineVideoSettings.getInstance().moSiteList;
			GUIOnlineVideos.SiteSettings loSite;
			GUIOnlineVideos.RssLink cat;
			foreach(string lsSiteId in lsSiteIds){
				loSite = loSiteList[lsSiteId];
				cat = new GUIOnlineVideos.RssLink();
				cat.name = loSite.name+"-Favorites";
				cat.url = "fav:"+loSite.id;
				cats.Add(cat);
				
			}
			cat = new GUIOnlineVideos.RssLink();
				cat.name = "Search-Favorites";
				cat.url = "fav:%{0}";
				cats.Add(cat);
			
			//SiteUtilFactory.getSiteUtil(
			
			return cats;
		}
		
	}
	
}
